home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-src / supp.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  13KB  |  465 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <limits.h>
  4. #include <string.h>
  5. #include <stddef.h>
  6. #include <stdarg.h>
  7. #include <ctype.h>
  8.  
  9. /* typenames */
  10. #define CHAR 1
  11. #define SHORT 2
  12. #define INT 3
  13. #define LONG 4
  14. #define FLOAT 5
  15. #define DOUBLE 6
  16. #define VOID 7
  17. #define POINTER 8
  18. #define ARRAY 9
  19. #define STRUCT 10
  20. #define UNION 11
  21. #define ENUM 12
  22. #define FUNKT 13
  23.  
  24. #define NQ 15   /* f&NQ gives type without any qualifiers */
  25. #define NU 31   /* f&NU gives type without any qualifiers but UNSIGNED */
  26.  
  27. /* operations on bit-vectors */
  28. #define BSET(array,bit) (array)[(bit)/CHAR_BIT]|=1<<((bit)%CHAR_BIT)
  29. #define BCLR(array,bit) (array)[(bit)/CHAR_BIT]&=~(1<<((bit)%CHAR_BIT))
  30. #define BTST(array,bit) ((array)[(bit)/CHAR_BIT]&(1<<((bit)%CHAR_BIT)))
  31.  
  32. /* type-qualifiers */
  33. #define UNSIGNED 16
  34. #define CONST 64
  35. #define VOLATILE 128
  36. #define UNCOMPLETE 256
  37. #define STRINGCONST 512
  38.  
  39. /*  macro for internal errors */
  40. #define ierror(a) error(-1,(a),__LINE__,FILE_)
  41.  
  42. /* this header is provided by the code generator */
  43. #include "machine.h"
  44.  
  45. #ifndef HAVE_INT_SIZET
  46. #define HAVE_INT_SIZET 0
  47. #endif
  48.  
  49. #ifndef PTRDIFF_T
  50. #define PTRDIFF_T INT
  51. #endif
  52.  
  53. struct fi_list {
  54.   char *identifier;
  55.   int class;
  56.   int type;
  57. };
  58.  
  59. /*  additional information for functions; used by the optimizer  */
  60. struct function_info{
  61.   struct IC *first_ic;    /* inline copy of function starts here */
  62.   struct IC *last_ic;     /*  "       "       "      ends here   */
  63.   struct Var *vars;       /* pointer to list of vars of that function */
  64.   char *inline_asm;       /* pointer to code for inline assembler */
  65.   char *translation_unit; /* string as ID for the translation-unit */
  66.   unsigned long flags;    /* misc flags, see above */
  67.   int unresolved_calls;   /* number of function-calls not yet resolved */
  68.   struct fi_list *calls;  /* list of functions called by that function */
  69.   /* registers used and modified by that function */
  70.   unsigned char regs_used[(MAXR+CHAR_BIT)/CHAR_BIT];
  71.   unsigned char regs_modified[(MAXR+CHAR_BIT)/CHAR_BIT];
  72.   /* variables used and modified by this function */
  73.   struct fi_list *used;
  74.   struct fi_list *modified;
  75. };
  76.  
  77. /*  struct for types.    */
  78. struct Typ{
  79.   int flags;  /*  see above   */
  80.   struct Typ *next;
  81.   struct struct_declaration *exact;   /* used for STRUCT/UNION/FUNKT  */
  82.   zlong size;     /*  used for ARRAY  */
  83. };
  84. #define TYPS sizeof(struct Typ)
  85.  
  86. struct Var{
  87.   int storage_class;  /* see below    */
  88.   int reg;            /* Var is assigned to this hard-reg */
  89.   int priority;       /* Priority to be used in simple_regs() */
  90.   int flags;          /* see below */
  91.   char *identifier;   /* name of the variable */
  92.   int nesting;        /* can be freely used by the frontend */
  93.   int index;          /* used by the optimizer */
  94.   zlong offset;       /* offset relative to the stack frame */
  95.   struct Typ *vtyp;   /* type of the variable */
  96.   struct const_list *clist;   /* initialized? */
  97.   struct Var *next;   /* pointer to next variable */
  98.   struct function_info *fi;   /* used by the optimizer */
  99.   struct Var *inline_copy;    /* used for function-inlining */
  100. #ifdef HAVE_TARGET_ATTRIBUTES
  101.   unsigned long tattr;        /* target-specific attributes */
  102. #endif
  103. };
  104.  
  105. /* available storage-classes */
  106. #define AUTO 1          /* var is allocated on the stack */
  107. #define REGISTER 2      /* basically the same as AUTO (C-only) */
  108. #define STATIC 3        /* var is static but has no external linkage */
  109. #define EXTERN  4       /* var is static and has external linkage */
  110. #define TYPEDEF 5       /* C-only */
  111.  
  112. /* available flags in struct Var */
  113. #define USEDASSOURCE 1      /* the var has been read */
  114. #define USEDASDEST 2        /* the var has been written */
  115. #define DEFINED 4           /* the var has been defined (i.e. storage will
  116.                                be allocated in the current file) */
  117. #define USEDASADR 8         /* the address of the var has been taken */
  118. #define GENERATED 16        /* code for static vars has been generated */
  119. #define CONVPARAMETER 32
  120. #define TENTATIVE 64        /* C-only */
  121. #define USEDBEFORE 128      /* used by the optimizer */
  122. #define INLINEV 256         /*  "               "    */
  123. #define PRINTFLIKE 512      /* C-only */
  124. #define SCANFLIKE 1024      /* C-only */
  125. #define NOTTYPESAFE 2048    /* used by the optimizer */
  126. #define DNOTTYPESAFE 4096   /*  "               "    */
  127. #define REGPARM 8192        /* the var is a register parameter */
  128. #define DBLPUSH 16384       /* parameter is also on the stack */
  129.  
  130. #define SLSIZE 32   /* realloc struct_lists in those steps */
  131.  
  132. /*  These structs are used to describe members of STRUCT/UNION or   */
  133. /*  parameters of FUNKT. Some of the entries in struct_list are not */
  134. /*  relevant for both alternatives.                                 */
  135. struct struct_declaration{
  136.   int count;  /* number of members/parameters */
  137.   struct struct_declaration *next;
  138.   struct struct_list (*sl)[];
  139. };
  140.  
  141. /* C-only */
  142. struct struct_list{
  143.   char *identifier;   /* name of the struct/union-tag */
  144.   struct Typ *styp;   /* type of the member/parameter */
  145.   int storage_class;  /* storage-class of function-parameter */
  146.   int reg;            /* register to pass function-parameter */
  147. };
  148.  
  149. /* This struct represents objects in the intermediate code. */
  150. struct obj{
  151.   int flags;      /* see below */
  152.   int reg;        /* number of reg if flags® */
  153.   struct Var *v;
  154.   struct AddressingMode *am;
  155.   union atyps{
  156.     zchar vchar;
  157.     zuchar vuchar;
  158.     zshort vshort;
  159.     zushort vushort;
  160.     zint vint;
  161.     zuint vuint;
  162.     zlong vlong;
  163.     zulong vulong;
  164.     zfloat vfloat;
  165.     zdouble vdouble;
  166.     zpointer vpointer;
  167.   }val;
  168. };
  169.  
  170.  
  171. /*  Available flags in struct obj.  */
  172.                     /*  KONST muss immer am kleinsten sein, um beim Swappen */
  173.                     /*  fuer available_expressions und Konstanten nach      */
  174.                     /*  rechts nicht in eine Endlosschleife zu kommen.      */
  175.  
  176. #define KONST 1     /*  The object is a constant. Its value is stored in    */
  177.                     /*  val.                                                */
  178. #define VAR 2       /*  The object is a variable (stored in v).             */
  179. #define SCRATCH 8   /*  The object is a temporary.                          */
  180. #define STACK 16    /*  obsolete                                            */
  181. #define DREFOBJ 32  /*  The object must be dereferenced.                    */
  182. #define REG 64      /*  The object is contained in a hardware register.     */
  183. #define VARADR 128  /*  The object is the address of a static variable.     */
  184. #define DONTREGISTERIZE 256 /*  Do not put this object into a register.     */
  185.  
  186.  
  187. /*  The quads in the intermediate code. */
  188. struct IC{
  189.   struct IC *prev;    /* pointer to the next IC */
  190.   struct IC *next;    /* pointer to the previous IC */
  191.   int code;           /* see below */
  192.   int typf;           /* usually type of the operands, see interface.doc */
  193.   int defindex;       /* used by optimizer */
  194.   int expindex;
  195.   int copyindex;
  196.   int change_cnt;
  197.   int use_cnt;
  198.   int line;           /* corresponding line in source file (or 0) */
  199.   struct varlist *change_list;    /* used by optimizer */
  200.   struct varlist *use_list;
  201.   struct obj q1;      /* source 1 */
  202.   struct obj q2;      /* source 2 */
  203.   struct obj z;       /* target */
  204.   char *file;         /* filename of the source file */
  205. };
  206. #define ICS sizeof(struct IC)
  207.  
  208.  
  209. /*  Available codes for struct IC. See interface.doc. */
  210. #define KOMMA 1
  211. #define ASSIGN 2
  212. #define ASSIGNADD 3
  213. #define ASSIGNSUB 4
  214. #define ASSIGNMULT 5
  215. #define ASSIGNDIV 6
  216. #define ASSIGNMOD 7
  217. #define ASSIGNAND 8
  218. #define ASSIGNXOR 9
  219. #define ASSIGNOR 10
  220. #define ASSIGNLSHIFT 11
  221. #define ASSIGNRSHIFT 12
  222. #define COND 13
  223. #define LOR 14
  224. #define LAND 15
  225. #define OR 16
  226. #define XOR 17
  227. #define AND 18
  228. #define EQUAL 19
  229. #define INEQUAL 20
  230. #define LESS 21
  231. #define LESSEQ 22
  232. #define GREATER 23
  233. #define GREATEREQ 24
  234. #define LSHIFT 25
  235. #define RSHIFT 26
  236. #define ADD 27
  237. #define SUB 28
  238. #define MULT 29
  239. #define DIV 30
  240. #define MOD 31
  241. #define NEGATION 32
  242. #define KOMPLEMENT 33
  243. #define PREINC 34
  244. #define POSTINC 35
  245. #define PREDEC 36
  246. #define POSTDEC 37
  247. #define MINUS 38
  248. #define CONTENT 39
  249. #define ADDRESS 40
  250. #define CAST 41
  251. #define CALL 42
  252. #define INDEX 43
  253. #define DPSTRUCT 44
  254. #define DSTRUCT 45
  255. #define IDENTIFIER 46
  256. #define CEXPR 47
  257. #define STRING 48
  258. #define MEMBER 49
  259. #define CONVCHAR 50
  260. #define CONVSHORT 51
  261. #define CONVINT 52
  262. #define CONVLONG 53
  263. #define CONVFLOAT 54
  264. #define CONVDOUBLE 55
  265. #define CONVVOID 56
  266. #define CONVPOINTER 57
  267. #define CONVUCHAR 58
  268. #define CONVUSHORT 59
  269. #define CONVUINT 60
  270. #define CONVULONG 61
  271. #define ADDRESSA 62
  272. #define FIRSTELEMENT 63
  273. #define PMULT 64
  274. #define ALLOCREG 65
  275. #define FREEREG 66
  276. #define PCEXPR 67
  277. #define TEST 68
  278. #define LABEL 69
  279. #define BEQ 70
  280. #define BNE 71
  281. #define BLT 72
  282. #define BGE 73
  283. #define BLE 74
  284. #define BGT 75
  285. #define BRA 76
  286. #define COMPARE 77
  287. #define PUSH 78
  288. #define POP 79
  289. #define ADDRESSS 80
  290. #define ADDI2P 81
  291. #define SUBIFP 82
  292. #define SUBPFP 83
  293. #define PUSHREG 84
  294. #define POPREG 85
  295. #define POPARGS 86
  296. #define SAVEREGS 87
  297. #define RESTOREREGS 88
  298. #define ILABEL 89
  299. #define DC 90
  300. #define ALIGN 91
  301. #define COLON 92
  302. #define GETRETURN 93
  303. #define SETRETURN 94
  304. #define MOVEFROMREG 95
  305. #define MOVETOREG 96
  306. #define NOP 97
  307.  
  308. #define arith(c) ((c)>=CHAR&&(c)<=DOUBLE)
  309.  
  310. extern char *typname[];
  311. extern zlong sizetab[16];
  312. extern char *storage_class_name[];
  313. extern char *ename[];
  314.  
  315. extern zlong align[16],maxalign;
  316.  
  317. /*  an empty string */
  318. extern char *empty;
  319.  
  320. extern zchar vchar; extern zuchar vuchar;
  321. extern zshort vshort; extern zushort vushort;
  322. extern zint vint; extern zuint vuint;
  323. extern zlong vlong; extern zulong vulong;
  324. extern zfloat vfloat; extern zdouble vdouble;
  325. extern zpointer vpointer;
  326.  
  327. #ifndef DEBUG
  328. extern int DEBUG;
  329. #endif
  330.  
  331. /*  used by the optimizer */
  332. struct varlist{
  333.   struct Var *v;
  334.   int flags;
  335. };
  336. #define VLS sizeof(struct varlist)
  337.  
  338.  
  339. extern struct IC *first_ic,*last_ic;
  340. extern int regs[MAXR+1],regsa[MAXR+1],regused[MAXR+1],regscratch[MAXR+1];
  341. extern zlong regsize[MAXR+1];
  342. extern struct Typ *regtype[MAXR+1];
  343. extern struct Var *regsv[MAXR+1];
  344. extern char *regnames[];
  345.  
  346. extern int label,return_label;
  347.  
  348. /* The structures used for available options of the code generator. */
  349. union ppi {char *p;long l;void (*f)(char *);};
  350. #define USEDFLAG 1
  351. #define STRINGFLAG 2
  352. #define VALFLAG 4
  353. #define FUNCFLAG 8
  354. extern int g_flags[MAXGF];
  355. extern char *g_flags_name[MAXGF];
  356. extern union ppi g_flags_val[MAXGF];
  357.  
  358. extern zlong max_offset;
  359.  
  360. extern int function_calls;
  361.  
  362. /*  Das haette ich gern woanders    */
  363. struct node{
  364.   int flags,lvalue,sidefx;
  365.   struct Typ *ntyp;
  366.   struct node *left;
  367.   struct node *right;
  368.   struct argument_list *alist;
  369.   char *identifier;
  370.   struct const_list *cl;
  371.   union atyps val;
  372.   struct obj o;
  373. };
  374.  
  375. typedef struct node *np;
  376.  
  377. #define NODES sizeof(struct node)
  378.  
  379. struct const_list{
  380.   union atyps val;
  381.   np tree;
  382.   struct const_list *other,*next;
  383. };
  384. #define CLS sizeof(struct const_list)
  385.  
  386. extern zlong t_min[];
  387. extern zulong t_max[];
  388. extern zlong char_bit;
  389.  
  390. extern char cg_copyright[];
  391.  
  392. #ifdef HAVE_TARGET_ATTRIBUTES
  393. extern char *g_attr_name[];
  394. #endif
  395.  
  396. extern int goto_used;
  397. extern int ic_count;
  398. extern int only_inline;
  399. extern int multiple_ccs;
  400. extern int float_used;
  401.  
  402.  
  403. extern struct IC *err_ic;
  404.  
  405.  
  406. extern long maxoptpasses,optflags,inline_size,unroll_size;
  407. extern long noaliasopt,fp_assoc;
  408. extern struct Var *vl1,*vl2,*vl3;
  409. extern int fline;
  410. extern char errfname[FILENAME_MAX+1];
  411.  
  412. /* functions which must be provided by the frontend */
  413. extern void add_IC(struct IC *);
  414. extern void error(int,...);
  415. extern struct Var *add_tmp_var(struct Typ *);
  416. extern void raus(void);
  417.  
  418. /* functions provided by supp.c */
  419. extern void free_IC(struct IC *);
  420. extern void insert_IC(struct IC *,struct IC *);
  421. extern void pric(FILE *,struct IC *);
  422. extern void pric2(FILE *,struct IC *);
  423. extern void probj(FILE *,struct obj *,int);
  424. extern void printzl(FILE *,zlong);
  425. extern void printzul(FILE *,zulong);
  426. extern void printzd(FILE *,zdouble);
  427. extern void printval(FILE *,union atyps *,int,int);
  428. extern void insert_const2(union atyps *,int);
  429. extern void prd(FILE *,struct Typ *);
  430. extern void freetyp(struct Typ *);
  431. extern struct Typ *clone_typ(struct Typ *);
  432. extern zlong szof(struct Typ *);
  433. extern zlong falign(struct Typ *);
  434. extern void eval_const(union atyps *,int);
  435. extern struct function_info *new_fi(void);
  436. extern void free_fi(struct function_info *);
  437.  
  438. extern void optimize(long, struct Var *);
  439. extern void remove_IC(struct IC *);
  440. extern void *mymalloc(size_t);
  441. extern void simple_regs(void);
  442.  
  443.  
  444. /*  functions provided by the code generator */
  445. extern int regok(int,int,int);
  446. extern int freturn(struct Typ *);
  447. extern void gen_code(FILE *,struct IC *,struct Var *,zlong);
  448. extern int init_cg(void);
  449. extern void cleanup_cg(FILE *);
  450. extern int dangerous_IC(struct IC *);
  451. extern void gen_dc(FILE *,int,struct const_list *);
  452. extern void gen_ds(FILE *,zlong,struct Typ *);
  453. extern void gen_var_head(FILE *,struct Var *);
  454. extern void gen_align(FILE *,zlong);
  455. extern int shortcut(int, int);
  456. extern int must_convert(np,int);
  457.  
  458. /* additional declarations for targets which pass arguments in */
  459. /* registers by default.                                       */
  460. #ifdef HAVE_REGPARMS
  461. extern struct reg_handle empty_reg_handle;
  462. extern int reg_parm(struct reg_handle *, struct Typ *,int);
  463. #endif
  464.  
  465.